# 数据集验证，需要加载的包库
import os
from PIL import Image
from matplotlib import pyplot as plt
import xml
import cv2 as cv
import numpy as np
import json
import math
from scipy.spatial import distance
from collections import OrderedDict
import time
import pandas as pds
from torch.utils.data import DataLoader
from torchvision import models
import torch
import torch.nn as nn
from utilour.datasetLoader import MyDataset
import torch.optim as optimer
from logdir import loginfo
from utilour.tool import calaccurary,visualize_cam
from torchsummary import summary
from utilour.gradcadpp import GradCAM
import torchvision
from torchvision.utils import make_grid, save_image
import copy
from utilour.ConvCalAnalys import ModelCalAnalys


# 加载数据
csvpath="/media/gis/data/jupyterlabhub/gitcode/hrx/dataset/train_test_vail.csv" # 文件路径
traindataset=MyDataset(csvpath,"train")
vaildataset=MyDataset(csvpath,"vail")
testdataset=MyDataset(csvpath,"test")
trainLoader=DataLoader(dataset=traindataset,batch_size=8,num_workers=8)
vailLoader=DataLoader(dataset=vaildataset,batch_size=8,num_workers=8)
testLoader=DataLoader(dataset=testdataset,batch_size=8,num_workers=8)


# 加载模型--修改模型
resnet50cpk=torch.load(os.path.join(".","modelRecord","resnet50.pkl"))
summary(resnet50cpk,input_size=(3,217,217))


print(resnet50cpk._modules.keys())
print(resnet50cpk._modules["layer1"][0].conv1) # 这样获取所有的层


calmode=ModelCalAnalys(resnet50cpk)

for step,(data,label,imgpath) in  enumerate(testLoader):
    """测试波段运行"""
    data=data.cuda()
    label=label.cuda()
    tlabels=calmode.forward(data)
    tlabels.detach().cpu().numpy()
    print(label.size())
    imglist=calmode.saveImage(label,tlabels)
    break
    pass

# 开始输出图片，使用 matplotlib 绘制图片
# 这里按照一个批次生成一个绘画结果
def outcalInfoOfConv(calmode):
    pass


